<template>
  <div class="app-main-box">

    <!-- 1.发起对账导入文件页面 -->
    <div v-show="activePage == 'first'" class="page-first-container">
      <!-- 1.到端数据 -->
      <div class="modal-content">
        <el-checkbox v-model="checked_end" label="到端数据" size="large" disabled />
        <div class="form-content">
          <!-- 已选择文件 -->
          <div v-if="fileList.length" class="preview-file-content">
            <div class="left">
              <svg-icon :icon-class="getExtension(current_file.name)" style="width: 100%;height: 100%;" />
            </div>
            <div class="file-info">
              <div class="file-name">{{ current_file.name }}</div>
              <span v-if="current_file.size / 1024 > 1024" class="file-size">{{ (current_file.size / 1024 /
                1024).toFixed(2) }}MB</span>
              <span v-else class="file-size">{{ (current_file.size / 1024).toFixed(2) }}KB</span>
            </div>
            <div class="right">
              <div class="preview-file" @click="handlePreview">
                <el-icon>
                  <View />
                </el-icon>
              </div>
              <div class="delete-file" @click="removeFileList">
                <el-icon>
                  <Close />
                </el-icon>
              </div>
            </div>
          </div>

          <!-- 未选择文件 -->
          <div v-if="!fileList.length" class="select-file">
            <div class="select-file-content">
              <el-upload class="upload-demo" accept=".csv, .xls, .xlsx" :on-change="handleChange" :auto-upload="false"
                :multiple="false">
                <!-- (未上传)点按钮选取文件 -->
                <el-button type="primary">选择文件</el-button>
              </el-upload>
              <el-button link type="primary" icon="download" @click="downloadTemplate">下载导入模板</el-button>
            </div>
            <div class="select-file-tip">支持格式.xlsx，.xls，csv，文件大小不得大于5M，最多支持导入2000条数据</div>
          </div>

          <!-- 导入表格数据有误 -->
          <div class="upload-fail" v-if="errorList.length">
            <div class="instructment-tip">表格中存在错误,具体错误如下,请检查后重新导入...</div>
            <div class="upload-fail-table">
              <div class="infinite-list-wrapper">
                <ul class="list">
                  <li v-for="i in errorList" :key="i.rowIndex" class="list-item">{{ `第${i.rowIndex}行，${i.errorMsg}` }}
                  </li>
                </ul>
              </div>
            </div>
          </div>

          <!-- 导入表格数据有重复 -->
          <div class="upload-fail" v-if="duplicateData.length">
            <div class="instructment-tip">表格中有重复数据，以下为重复数据，请检查后重新导入</div>
            <div class="upload-fail-table" style="height: auto">
              <el-table class="global-border-radius-table" algin="center" :data="duplicateData" style="font-size: 12px;"
                max-height="282px">
                <el-table-column label="车牌号" prop="plateNo" min-width="114" :show-overflow-tooltip="true" />
                <el-table-column label="磅单号" prop="weightBillNo" min-width="180" :show-overflow-tooltip="true" />
                <el-table-column label="箱号" prop="containerNo" min-width="120" :show-overflow-tooltip="true" />
                <el-table-column label="过磅日期" prop="weightingDate" min-width="114" :show-overflow-tooltip="true" />
                <el-table-column label="货物名称" prop="cargo" :show-overflow-tooltip="true" />
                <el-table-column label="净重(吨)" prop="netWeight" :show-overflow-tooltip="true" />
              </el-table>
            </div>
          </div>

          <!-- 导入表格中重复数据文案 -->
          <div class="upload-fail" v-if="errorCode == 'DuplicateReceiptData' && !duplicateData.length">
            <div class="instructment-tip">表格中存在错误,具体错误如下,请检查后重新导入...

            </div>
            <div class="upload-fail-table">
              <div class="infinite-list-wrapper">
                <p style="text-align: left;color: #333;">{{ duplicate_content }}</p>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="divider"></div>

      <!-- 2.铁路数据 -->
      <div class="modal-content">
        <el-checkbox v-model="checked_railway" label="铁路数据" size="large" disabled />
        <div class="form-content">
          <el-form ref="formRailRef" :model="formRail" :rules="formRailRule">
            <el-form-item style="width: 100%;">
              <el-radio-group v-model="radio_railway" @change="changeRailwayRadio">
                <el-radio label="0" value="0">智能匹配</el-radio>
                <el-radio label="1" value="1">按日期选择</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item prop="dateRange_railway" v-if="radio_railway == 1" class="form-item">
              <template #label>
                <div class="label-wrap">
                  <span class="label-text">装车日期</span>
                  <span class="label-single">：</span>
                </div>
              </template>
              <el-date-picker v-model="formRail.dateRange_railway" value-format="YYYY-MM-DD" type="daterange"
                range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                :teleported="false"></el-date-picker>
            </el-form-item>
          </el-form>
        </div>
      </div>

      <div class="divider"></div>

      <!-- 3.发端数据 -->
      <div class="modal-content">
        <el-checkbox v-model="checked_start" label="发端数据" size="large" disabled />
        <div class="form-content">
          <el-form ref="formStartRef" :model="formStart" :rules="formStartRule">
            <el-form-item>
              <el-radio-group v-model="radio_start" @change="changeStartRadio">
                <el-radio label="0" value="0">智能匹配</el-radio>
                <el-radio label="1" value="1">按日期选择</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item class="form-item" prop="routeIds">
              <template #label>
                <div class="label-wrap">
                  <span class="label-text">线路</span>
                  <span class="label-single">：</span>
                </div>
              </template>
              <el-select v-model="formStart.routeIds" placeholder="请选择线路" filterable multiple :teleported="false"
                style="width: 100%;" clearable>
                <el-option v-for="item in routeOption" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
            <el-form-item prop="dateRange_start" v-if="radio_start == 1" class="form-item">
              <template #label>
                <div class="label-wrap">
                  <span class="label-text">发车日期</span>
                  <span class="label-single">：</span>
                </div>
              </template>
              <el-date-picker value-format="YYYY-MM-DD HH:mm:ss" v-model="formStart.dateRange_start"
                type="datetimerange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                :teleported="false"></el-date-picker>
            </el-form-item>
          </el-form>
        </div>
      </div>

      <!-- 文件预览传送门 -->
      <teleport to="body">
        <div class="global-preview-file-container" v-if="show_frame_view">
          <div v-loading="render_loading" element-loading-text="数据加载中..." style="width: 60%; height: 80%">
            <!-- <IFrame :src="file_url"></IFrame> -->
            <VueOfficeExcel :src="file_url" @rendered="rendered" style="width: 100%; height: 100%"></VueOfficeExcel>
          </div>
          <span class="global-viewer-close" @click="closePreviewFile">
            <el-icon>
              <Close />
            </el-icon>
          </span>
        </div>
      </teleport>

      <!-- 开始匹配 -->
      <div class="footer" style="display: flex;justify-content: left; padding-bottom: 30px">
        <el-button type="primary" @click="handleMatchSubmit" :loading="match_loading">匹配数据</el-button>
      </div>
    </div>

    <!-- 2.发起对账匹配结果表格页面 -->
    <div v-show="activePage == 'second'" class="page-second-container" v-loading="match_loading">
      <div class="func-btn">
        <el-button round type="default" icon="Back" @click="goBcak">返回</el-button>
      </div>

      <!-- 未成功匹配数据 -->
      <div v-if="waybillUnmatchedData.length" class="match-data-container">
        <div class="title-bar-container" style="padding: 0 24px;">
          <div class="global-title-bar">
            <div class="dot"></div>
            <div class="text">未成功匹配数据</div>
          </div>
          <el-popover popper-class="custom-popper" placement="right" title="未成功匹配说明" :width="400" trigger="hover"
            :content="waybillUnmatchedContent">
            <template #reference>
              <el-icon>
                <InfoFilled />
              </el-icon>
            </template>
          </el-popover>
        </div>
        <div class="global-table-container" style="margin-top: 20px;">
          <vxe-table border align="center" show-overflow max-height="215" highlight-hover-row
            :row-config="{ height: 35 }" :scroll-y="{ enabled: true, gt: 0 }" :scroll-x="{ enabled: true, gt: 0 }"
            :data="waybillUnmatchedData" :header-cell-style="grayColor">
            <!-- 车牌号 磅单号 箱号  过磅日期   -->
            <vxe-column type="seq" width="70"></vxe-column>
            <vxe-colgroup title="到端">
              <vxe-column title="车牌号" field="receiptPlateNo" min-width="100">
              </vxe-column>
              <vxe-column title="磅单号" field="receiptWeightBillNo" min-width="180">
              </vxe-column>
              <vxe-column title="箱号" field="receiptContainerNo" min-width="120">
              </vxe-column>
              <vxe-column title="过磅日期" field="receiptWeightingDate" min-width="120">
              </vxe-column>
            </vxe-colgroup>
            <!-- 车牌号 车辆来源 磅单号 箱号 线路 货物 发车时间 -->
            <vxe-colgroup title="发端" header-class-name="start-front">
              <vxe-column title="车牌号" field="originatingPlateNo" min-width="100"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="磅单号" field="originatingWeightBillNo" min-width="180"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="箱号" field="originatingContainerNo" min-width="120"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="线路名称" field="originatingRouteName" min-width="120"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="货物" field="originatingCargo" min-width="120"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="发车时间" field="originatingDepartureTime" min-width="150"
                header-class-name="start-front"></vxe-column>
            </vxe-colgroup>
            <!-- 磅单号 车号 箱号 运单号  发站 到站 装车日期 -->
            <vxe-colgroup title="铁路" header-class-name="middle-front">
              <vxe-column title="磅单号" field="railwayWeightBillNo" min-width="180"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="车号" field="railwayTrainNo" min-width="100"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="箱号" field="railwayContainerNo" min-width="120"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="运单号" field="railwayBillNo" min-width="180"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="发站" field="railwayDepartureStation" min-width="100"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="到站" field="railwayArrivalStation" min-width="100" header-class-name="middle-front">
              </vxe-column>
              <vxe-column title="装车日期" field="railwayLoadingDate" min-width="150"
                header-class-name="middle-front"></vxe-column>
            </vxe-colgroup>
          </vxe-table>
        </div>
      </div>

      <!-- 有重复匹配数据 -->
      <div v-if="waybillDuplicatedData.length" class="match-data-container">
        <div class="title-bar-container" style="padding: 0 24px;">
          <div class="global-title-bar">
            <div class="dot"></div>
            <div class="text">重复匹配数据</div>
          </div>
          <el-popover popper-class="custom-popper" placement="right" title="重复匹配说明" :width="400" trigger="hover"
            :content="waybillDuplicatedContent">
            <template #reference>
              <el-icon>
                <InfoFilled />
              </el-icon>
            </template>
          </el-popover>
        </div>
        <div class="global-table-container" style="margin-top: 20px;">
          <vxe-table border align="center" show-overflow max-height="215"
            :row-config="{ height: 35 }"  :data="waybillDuplicatedData"
            :header-cell-style="grayColor" ref="xTable" :mergeCells="mergeRules">
            <vxe-column type="seq" width="70"></vxe-column>
            <!-- 车牌号 磅单号 箱号  过磅日期   -->
            <vxe-colgroup title="到端">
              <vxe-column title="车牌号" field="receiptPlateNo" min-width="100">
              </vxe-column>
              <vxe-column title="磅单号" field="receiptWeightBillNo" min-width="180">
              </vxe-column>
              <vxe-column title="箱号" field="receiptContainerNo" min-width="120">
              </vxe-column>
              <vxe-column title="过磅日期" field="receiptWeightingDate" min-width="120">
              </vxe-column>
            </vxe-colgroup>
            <!-- 车牌号 车辆来源 磅单号 箱号 线路 货物 发车时间 -->
            <vxe-colgroup title="发端" header-class-name="start-front">
              <vxe-column title="车牌号" field="originatingPlateNo" min-width="100"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="磅单号" field="originatingWeightBillNo" min-width="180"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="箱号" field="originatingContainerNo" min-width="120"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="线路名称" field="originatingRouteName" min-width="120"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="货物" field="originatingCargo" min-width="120"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="发车时间" field="originatingDepartureTime" min-width="150"
                header-class-name="start-front"></vxe-column>
            </vxe-colgroup>
            <!-- 磅单号 车号 箱号 运单号  发站 到站 装车日期 -->
            <vxe-colgroup title="铁路" header-class-name="middle-front">
              <vxe-column title="磅单号" field="railwayWeightBillNo" min-width="180"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="车号" field="railwayTrainNo" min-width="100"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="箱号" field="railwayContainerNo" min-width="120"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="运单号" field="railwayBillNo" min-width="180"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="发站" field="railwayDepartureStation" min-width="100"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="到站" field="railwayArrivalStation" min-width="100" header-class-name="middle-front">
              </vxe-column>
              <vxe-column title="装车日期" field="railwayLoadingDate" min-width="150"
                header-class-name="middle-front"></vxe-column>
            </vxe-colgroup>

          </vxe-table>
        </div>
      </div>

      <!-- 匹配结果 -->
      <div class="match-data-container">
        <div class="flex-space-between" style="padding: 0 24px;">
          <div class="global-title-bar">
            <div class="dot"></div>
            <div class="text">匹配结果</div>
          </div>
          <div class="flex-right" v-if="false">
            <el-button round type="default" plain style="margin-bottom: 20px" icon="Download"
              @click="exportData">导出数据</el-button>
          </div>
        </div>
        <div class="global-table-container" style="margin-top: 20px;">
          <vxe-table :row-config="{ height: 35 }" row-class-name="vxe-table-row" border align="center" show-overflow
            max-height="605" highlight-hover-row :scroll-y="{ enabled: true, gt: 0 }"
            :scroll-x="{ enabled: true, gt: 0 }" :data="resultData" :header-cell-style="grayColor">
            <vxe-column type="seq" width="70"></vxe-column>
            <!-- 车牌号 磅单号 箱号  过磅日期   -->
            <vxe-colgroup title="到端">
              <vxe-column title="车牌号" field="receiptPlateNo" min-width="100">
              </vxe-column>
              <vxe-column title="磅单号" field="receiptWeightBillNo" min-width="180">
              </vxe-column>
              <vxe-column title="箱号" field="receiptContainerNo" min-width="120">
              </vxe-column>
              <vxe-column title="过磅日期" field="receiptWeightingDate" min-width="120">
              </vxe-column>
            </vxe-colgroup>
            <!-- 车牌号 车辆来源 磅单号 箱号 线路 货物 发车时间 -->
            <vxe-colgroup title="发端" header-class-name="start-front">
              <vxe-column title="车牌号" field="originatingPlateNo" min-width="100"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="磅单号" field="originatingWeightBillNo" min-width="180"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="箱号" field="originatingContainerNo" min-width="120"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="线路名称" field="originatingRouteName" min-width="120"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="货物" field="originatingCargo" min-width="120"
                header-class-name="start-front"></vxe-column>
              <vxe-column title="发车时间" field="originatingDepartureTime" min-width="150"
                header-class-name="start-front"></vxe-column>
            </vxe-colgroup>
            <!-- 磅单号 车号 箱号 运单号  发站 到站 装车日期 -->
            <vxe-colgroup title="铁路" header-class-name="middle-front">
              <vxe-column title="磅单号" field="railwayWeightBillNo" min-width="180"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="车号" field="railwayTrainNo" min-width="100"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="箱号" field="railwayContainerNo" min-width="120"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="运单号" field="railwayBillNo" min-width="180"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="发站" field="railwayDepartureStation" min-width="100"
                header-class-name="middle-front"></vxe-column>
              <vxe-column title="到站" field="railwayArrivalStation" min-width="100" header-class-name="middle-front">
              </vxe-column>
              <vxe-column title="装车日期" field="railwayLoadingDate" min-width="150"
                header-class-name="middle-front"></vxe-column>
            </vxe-colgroup>
          </vxe-table>
        </div>
      </div>

      <div class="match-data-footer">
        <div class="btn-list">
          <el-button type="default" @click="handleSubmitAgain" :loading="match_loading">重新匹配</el-button>
          <el-button type="primary" @click="handleGenerate">生成对账单</el-button>
        </div>
      </div>
    </div>

    <!-- 3.发起对账成功页面 -->
    <div v-if="activePage == 'third'" class="page-third-container">
      <el-icon :size="70" color="#00b42a">
        <SuccessFilled />
      </el-icon>
      <span class="operate-title">操作成功</span>
      <span class="operate-text">对账单已经生成成功,您可以在对账单列表进行查看</span>
      <div class="btn-list">
        <el-button @click="closeSuccessPage">返回</el-button>
        <el-button type="primary" @click="handelDownLoad">下载Excel对账单</el-button>
        <el-button type="primary" @click="handelViewInfo">查看对账单详情</el-button>
      </div>
    </div>

    <!-- 生成对账单对话框 -->
    <el-dialog title="生成对账单" v-model="generate_dialog" width="800px" style="min-width: 750px" append-to-body>
      <el-form class="form-generate" :model="formGenerate" label-width="120px" :rules="formGenerateRules"
        ref="formGenerateRef">
        <el-form-item label="标题：" prop="title" class="form-items">
          <el-input v-noSpace v-model="formGenerate.title" class="form-input" placeholder="请输入标题" clearable></el-input>
        </el-form-item>
        <el-form-item label="应收金额：" prop="amountReceivable" class="form-items">
          <el-input v-noSpace v-model="formGenerate.amountReceivable" class="form-input" placeholder="请输入应收金额"
            clearable></el-input>
        </el-form-item>
        <el-form-item label="备注：" prop="remark" class="form-items" style="width: 100%">
          <el-input v-model="formGenerate.remark" type="textarea" :autosize="{ minRows: 2, maxRows: 5 }"
            placeholder="请输入备注" maxlength="200" show-word-limit clearable>
          </el-input>
        </el-form-item>
      </el-form>

      <div class="dialog-footer" style="margin-top: 2px;">
        <el-button type="primary" @click="submitGenerate" :loading="generate_loading">确 定</el-button>
        <el-button @click="cancelGenerate">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script setup name="InitiateReconciliation">
import * as XLSX from 'xlsx';
import IFrame from '@/components/iFrame'
import { ElMessage } from 'element-plus'
import { ref, reactive, toRefs, onBeforeMount, onMounted, onBeforeUnmount, watchEffect, computed, getCurrentInstance, onActivated, onDeactivated } from 'vue';
import { matchDataApi, submitDataApi, downloadApi } from "@/api/financeManagement/upstreamReconciliation/initiateReconciliation";
import { getRouteSimpleListApi } from "@/api/common";
import useCommonStore from '@/store/modules/common'
const router = useRouter();
const { proxy } = getCurrentInstance();
let xTable = ref(null)
let mergeRules = ref([])
let reconciliationId = ref("") // 生成对账单成功之后的结果id,下载对账单Excel
let radio_railway = ref("0")
let radio_start = ref("0")
let routeOption = ref([])  // 线路下拉列表
let activePage = ref('first')
let checked_railway = ref(true) // 铁路
let checked_start = ref(true)  // 发端
let checked_end = ref(true)  // 发端
let render_loading = ref(false) // 文件渲染loading
let generate_dialog = ref(false) // 生成对账单对话框
let generate_loading = ref(false) // 生成对账单确定按钮loading
let match_loading = ref(false) // 匹配数据loading
let current_file = ref({})
let fileList = ref([])
let file_url = ref('') // 文件预览地址
let show_frame_view = ref(false) // 文件预览frame
let errorList = ref([])
let errorCode = ref('')
let duplicateData = ref([])  // 导入出错重复数据
let waybillUnmatchedData = ref([]) // 未匹配到的数据
let waybillDuplicatedData = ref([]) // 匹配重复数据
let resultData = ref([])  // 匹配结果
let duplicate_content = ref('') // 接口返回重复标识,没有返回重复数据(搞不懂???)
const waybillUnmatchedContent = ref(`
  在数据匹配过程中，我们会将到端的数据与铁路的数据进行匹配。
  匹配的标准是：箱号相同，且日期差在两天以内。如果到端的数据成功匹配到铁路对应数据，则视为匹配成功。如果未匹配到铁路数据则视为匹配失败。
  主要原因可能是铁路数据缺失或箱号错误等原因，请检查和处理后重新匹配。`)
const waybillDuplicatedContent = ref(`
  在数据匹配过程中，我们会将到端的数据与铁路的数据进行匹配。
  匹配的标准是：箱号相同，且日期差在两天以内。如出现同一条到端数据匹配到多条铁路数据，则视为重复匹配。
  主要原因可能是铁路数据重复或箱号错误等原因，请检查和处理后重新匹配。`)
let data = reactive({
  formGenerateRules: {
    title: [{ required: true, message: "标题不能为空", trigger: "blur" }],
    amountReceivable: [
      { required: true, message: "应收金额不能为空", trigger: "blur" },
      { pattern: /^(?!0(\.0+)?$)\d+(\.\d+)?$/, message: '仅允许输入大于0的小数和整数', trigger: 'blur' },
      { pattern: /^(?!0\d)(\d+(\.\d*)?|\.\d+)$/, message: '输入内容不合法', trigger: 'blur' },
    ],
  },
  formStartRule: {
    routeIds: [{ required: true, message: '请选择线路', trigger: 'change' }],
    dateRange_start: [{ required: true, message: '请选择发车日期', trigger: 'change' }]
  },
  formRailRule: {
    dateRange_railway: [{ required: true, message: '请选择装车日期', trigger: 'change' }],
  },
  formGenerate: {},
  formStart: {
    routeIds: []
  },
  formRail: {}
});
const { formGenerate, formGenerateRules, formRail, formStart, formRailRule, formStartRule } = toRefs(data);
onBeforeMount(() => {
  getPageState()
})
onMounted(() => {
})
onActivated(() => {
})
onDeactivated(() => {
})
/** 在此周期中管理状态 */
onBeforeUnmount(() => {
  let initiate_reconciliation = {
    reconciliationId: reconciliationId.value, // 生成对账单成功之后的结果id,下载对账单Excel
    radio_railway: radio_railway.value, // 铁路单选（0-智能匹配，1-时间选择）
    radio_start: radio_start.value, // 发端
    activePage: activePage.value,
    current_file: current_file.value, // 选择完后本地文件对象
    fileList: fileList.value, // 选择的文件列表，
    file_url: file_url.value, // 预览文件使用文件url
    show_frame_view: show_frame_view.value, // 显示文件预览条件
    formRail: formRail.value,
    formStart: formStart.value,
    formGenerate: formGenerate.value, // 生成对账单的表单
    errorList: errorList.value,
    errorCode: errorCode.value,
    duplicateData: duplicateData.value,
    waybillUnmatchedData: waybillUnmatchedData.value,
    waybillDuplicatedData: waybillDuplicatedData.value, // 发端时间区间
    resultData: resultData.value,
    mergeRules: mergeRules.value
  }
  writeData(initiate_reconciliation)
})

/** 获取文件后缀名 */
function getExtension(filename) {
  if (filename) {
    return filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
  }
}

/** 写入数据 */
async function writeData(data) {
  const res = await useCommonStore().setCommonData(data)
  console.log(res, '写入数据');
}

/** 定义一个默认主动执行函数获取当前页面的状态 */
async function getPageState() {
  let result = await useCommonStore().getCommonData()
  reconciliationId.value = result.reconciliationId // 生成对账单成功之后的结果id下载对账单Excel
  radio_railway.value = result.radio_railway // 铁路单选（0-智能匹配，1-时间选择）
  radio_start.value = result.radio_start // 发端单选
  activePage.value = result.activePage
  current_file.value = result.current_file // 选择的文件列表，
  fileList.value = result.fileList // 选择的文件列表，
  file_url.value = result.file_url // 预览文件使用文件url
  show_frame_view.value = result.show_frame_view // 显示文件预览条件
  formStart.value = result.formStart
  formRail.value = result.formRail
  formGenerate.value = result.formGenerate // 生成对账单的表单
  errorList.value = result.errorList
  errorCode.value = result.errorCode
  duplicateData.value = result.duplicateData
  waybillUnmatchedData.value = result.waybillUnmatchedData
  waybillDuplicatedData.value = result.waybillDuplicatedData // 发端时间区间
  resultData.value = result.resultData
  mergeRules.value = result.mergeRules
}

/** 表头样式 */
const grayColor = ({ column }) => {
  if (column.headerClassName == 'start-front') {
    return {
      backgroundColor: '#f2f4f7 !important',
      color: '#515a6e',
      textAlign: 'center',
      height: '40px !important'
    }
  }
  else if (column.headerClassName == 'middle-front') {
    return {
      backgroundColor: '#e1f3d8 !important',
      color: '#515a6e',
      textAlign: 'center',
      height: '40px !important'
    }
  } else {
    return {
      backgroundColor: '#ecf5ff !important',
      color: '#515a6e',
      textAlign: 'center',
      height: '40px !important'
    }
  }
}

/** 文件预览渲染完成 */
function rendered() {
  console.log('渲染完成');
  render_loading.value = false
}

/** 线路下拉列表 */
function getRouteSimpleList() {
  getRouteSimpleListApi().then(response => {
    if (response.code === 1) {
      routeOption.value = response.data
    } else {
      ElMessage({ message: response.message, type: 'error' })
    }
  }).catch(err => {
  })
}

/** 铁路数据复选框状态变化 */
function changeRailwayRadio(radio) {
  radio_railway.value == radio
}

/** 发端数据复选框状态变化 */
function changeStartRadio(radio) {
  radio_railway.value == radio
}

/** 到端数据文件状态变化 */
function handleChange(file) {
  removeFileList()
  let supposeType = ['xls', 'xlsx', 'csv']
  /** 获取文件后缀名 */
  let fileRaw = file.raw || file.file
  if (supposeType.includes(getExtension(fileRaw.name))) {
    current_file.value = file.raw || file.file
    // 将最新的文件加入到fileList中
    fileList.value = [current_file.value];
  } else {
    ElMessage({ message: '文件类型暂不支持，请重新上传', type: 'error', duration: 2000 })
  }
}

/** 关闭iframe文件预览按钮 */
function closePreviewFile() {
  render_loading.value = false
  show_frame_view.value = false
}

/** 预览文件 */
async function handlePreview() {
  render_loading.value = true
  show_frame_view.value = true
  console.log(current_file.value, '文件对象')
  if (current_file.value.type == 'application/vnd.ms-excel' || current_file.value.type == 'text/csv') {
    let binaryFile = await converXlsToXlsx(current_file.value)
    let base64_file = await getBase64(binaryFile)
    file_url.value = base64_file
  } else {
    let base64_file = await fileToBase64(current_file.value)
    file_url.value = base64_file
  }
  // file_url.value = 'https://view.officeapps.live.com/op/view.aspx?src=https://bituo-logistics-saas.oss-cn-beijing.aliyuncs.com/web/excel/template/%E5%88%B0%E7%AB%AF%E6%95%B0%E6%8D%AE%E6%A8%A1%E6%9D%BF.xlsx'
  // https://flyfish.dev/%E6%95%B0%E6%8D%AE%E4%B8%AD%E5%8F%B0%E7%AC%94%E8%AE%B0(1).docx
}

/** File转Base64 */
async function fileToBase64(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onload = function (event) {
      resolve(event.target.result);
    };
    reader.readAsDataURL(file);
    reader.onerror = reject;
  });
}

// 二进制流转换为base64 格式。
function getBase64(file) {
  return new Promise((resolve, reject) => {
    const blob = new Blob([file], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }); // 必须指定type类型
    const reader = new FileReader();
    reader.onload = () => resolve(reader.result);
    reader.readAsDataURL(blob);
    reader.onerror = (error) => reject(error);
  });
}

/** 文件格式转换 */
function converXlsToXlsx(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onload = function (e) {
      const data = new Uint8Array(e.target.result);
      const workbook = XLSX.read(data, { type: 'array' });
      const xlsxBinary = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
      resolve(xlsxBinary);
    }
    reader.onerror = reject;
    reader.readAsArrayBuffer(file);
  })
}

/** 删除所选文件 */
function removeFileList() {
  current_file.value = {}
  file_url.value = ''
  fileList.value = [];
  errorList.value = []
  duplicateData.value = []
  errorCode.value = ''
}

/** 导出匹配数据 */
function exportData() { }

/** 提交匹配数据 */
function handleMatchSubmit() {
  if (!fileList.value.length) {
    ElMessage({ message: '未选择到端文件!,请选择文件再尝试匹配!', type: 'error', duration: 2000 })
  } else {
    matchData()
  }
}

/** 重新匹配 */
async function handleSubmitAgain() {
  await matchData()
}

/** 打开生成对账单dialog*/
async function handleGenerate() {
  reset()
  await generateBymatchData()
  generate_dialog.value = true
}

/** 生成对账单确认 */
function submitGenerate() {
  proxy.$refs["formGenerateRef"].validate((valid) => {
    if (valid) {
      generateData()
    }
  })
}

/** 根据匹配结果返回错误信息 */
function generateBymatchData() {
  return new Promise((resolve, reject) => {
    if (waybillUnmatchedData.value.length) {
      ElMessage({ message: '有未完全匹配的数据，请检查后重试!', type: 'error', duration: 2000 })
      return false
    } else if (waybillDuplicatedData.value.length) {
      ElMessage({ message: '有重复匹配数据，请检查后重试!', type: 'error', duration: 2000 })
      return false
    } else {
      resolve()
    }
  })
}

/** 生成对账单接口 */
function generateData() {
  generate_loading.value = true
  submitDataApi(formGenerate.value).then((response) => {
    if (response.code === 1) {
      generate_loading.value = false
      generate_dialog.value = false
      reconciliationId.value = response.data?.id
      activePage.value = 'third'
    } else {
      generate_loading.value = false
      ElMessage({ message: response.message || '操作失败！', type: 'error', duration: 2000 })
    }
  }).catch(() => {
    generate_loading.value = false
  })
}

/** 下载Excel账单 */
function handelDownLoad() {
  download()
}

/** 查看对账单详情 */
async function handelViewInfo() {
  let id = reconciliationId.value
  clearPage()
  await router.push({
    path: '/financeManagement/upstreamReconciliation/railwayReconciliationInfo',
    query: {
      id: id
    }
  })
}

/** 清空当前页面所存数据 */
function clearPage() {
  reconciliationId.value = '' // 生成对账单成功之后的结果id下载对账单Excel
  radio_railway.value = '0' // 铁路单选（0-智能匹配，1-时间选择）
  radio_start.value = '0' // 发端
  activePage.value = 'first'
  current_file.value = {} // 选择完后本地文件对象
  fileList.value = [] // 选择的文件列表，
  file_url.value = '' // 预览文件使用文件url
  show_frame_view.value = false // 显示文件预览条件
  formGenerate.value = {} // 生成对账单的表单
  formStart.value = {}
  formRail.value = {}
  errorCode.value = ''
  errorList.value = []
  duplicateData.value = []
  waybillUnmatchedData.value = []
  waybillDuplicatedData.value = [] // 发端时间区间
  resultData.value = []
}

/** 下载对账单API */
async function download() {
  downloadApi({ reconciliationId: reconciliationId.value }).then((response) => {
    // const disposition = response.headers['content-disposition'];
    // const matchArray = disposition.match(/filename="(.*)"/);
    // const filename = matchArray[1];
    let filename = formGenerate.value.title + '.xlsx'
    const url = window.URL.createObjectURL(response);
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', filename);
    document.body.appendChild(link);
    link.click()
    document.body.removeChild(link); // 下载完成后移除元素
    window.URL.revokeObjectURL(url); // 释放URL对象
  })
}

/** 重置表单 */
function reset() {
  let matchId = formGenerate.value.matchId
  formGenerate.value = {
    title: undefined,
    amountReceivable: undefined,
    remark: undefined,
    matchId: matchId
  }
}

/** 取消生成对账单 */
function cancelGenerate() {
  generate_dialog.value = false
}

/** 匹配数据接口 */
async function matchData() {
  const p1 = new Promise((resolve, reject) => {
    proxy.$refs['formStartRef'].validate(valid => {
      if (valid) {
        resolve()
      }
    })
  })
  const p2 = new Promise((resolve, reject) => {
    proxy.$refs['formRailRef'].validate(valid => {
      if (valid) {
        resolve()
      }
    })
  })
  Promise.all([p1, p2]).then(async () => {
    match_loading.value = true
    // 判断
    const { dateRange_start, routeIds } = formStart.value
    const { dateRange_railway } = formRail.value
    let railway_params = proxy.addDateRange({}, dateRange_railway, 'Date')
    let originating_params = proxy.addDateRange({ routeIds: routeIds }, dateRange_start, 'Time')
    const railway = new Blob([JSON.stringify(railway_params)], { type: 'application/json;charset=utf-8' });
    const originating = new Blob([JSON.stringify(originating_params)], { type: 'application/json;charset=utf-8' });
    const routeId = new Blob([JSON.stringify(routeIds)], { type: 'application/json;charset=utf-8' });
    let formData = new FormData();
    formData.append("receiptDataFile", current_file.value);
    formData.append('railway', railway);
    formData.append('originating', originating);
    formData.append('routeIds', routeId);
    await matchDataApi(formData).then((response) => {
      if (response.code === 1) {
        resultData.value = response.data.waybillMatchData
        waybillUnmatchedData.value = response.data.waybillUnmatchedData
        formGenerate.value.matchId = response.data.matchId
        activePage.value = 'second'
        match_loading.value = false
        /** 合并单元格 */
        let mergeData = response.data.waybillDuplicatedData
        // 测试数据
        // let mergeData = [
        //     {
        //       receiptPlateNo: '111',receiptWeightBillNo: '222',receiptContainerNo: '333',receiptWeightingDate: '444',
        //       railwayWeightBillNo: '11',railwayContainerNo: '11',railwayTrainNo: '11',railwayCoverClothNo:'11',
        //       railwayBillNo: '11',railwayCargo: '11',railwayWeight: '11', railwayDepartureStation: '11',railwayArrivalStation: '11',
        //       railwayConsignor: '11', railwayConsignee: '11',railwayLoadingDate: '11',
        //       originatingId: null,originatingPlateNo: '',originatingWeightBillNo: '',originatingContainerNo: '',
        //       originatingRouteName: '',originatingCargo: '',originatingDepartureTime: '',
        //       railwayId: 'id'
        //     },
        //     {
        //       receiptPlateNo: '111',receiptWeightBillNo: '222',receiptContainerNo: '333',receiptWeightingDate: '444',
        //       railwayWeightBillNo: '11',railwayContainerNo: '11',railwayTrainNo: '11',railwayCoverClothNo:'11',
        //       railwayBillNo: '11',railwayCargo: '11',railwayWeight: '11', railwayDepartureStation: '11',railwayArrivalStation: '11',
        //       railwayConsignor: '11', railwayConsignee: '11',railwayLoadingDate: '11',
        //       originatingId: null,originatingPlateNo: '',originatingWeightBillNo: '',originatingContainerNo: '',
        //       originatingRouteName: '',originatingCargo: '',originatingDepartureTime: '',
        //       railwayId: 'id',
        //     },

        //     {
        //       receiptPlateNo: '111',receiptWeightBillNo: '222',receiptContainerNo: '333',receiptWeightingDate: '444',
        //       railwayWeightBillNo: '12',railwayContainerNo: '12',railwayTrainNo: '12',railwayCoverClothNo:'12',
        //       railwayBillNo: '12',railwayCargo: '12',railwayWeight: '12', railwayDepartureStation: '12',railwayArrivalStation: '12',
        //       railwayConsignor: '12', railwayConsignee: '12',railwayLoadingDate: '12',
        //       originatingId: 12,originatingPlateNo: '',originatingWeightBillNo: '',originatingContainerNo: '',
        //       originatingRouteName: '',originatingCargo: '',originatingDepartureTime: '',
        //       railwayId: 'id'
        //     },
        //     {
        //       receiptPlateNo: '111',receiptWeightBillNo: '222',receiptContainerNo: '333',receiptWeightingDate: '444',
        //       railwayWeightBillNo: '12',railwayContainerNo: '12',railwayTrainNo: '12',railwayCoverClothNo:'12',
        //       railwayBillNo: '12',railwayCargo: '12',railwayWeight: '12', railwayDepartureStation: '12',railwayArrivalStation: '12',
        //       railwayConsignor: '12', railwayConsignee: '12',railwayLoadingDate: '12',
        //       originatingId: 12,originatingPlateNo: '',originatingWeightBillNo: '',originatingContainerNo: '',
        //       originatingRouteName: '',originatingCargo: '',originatingDepartureTime: '',
        //       railwayId: 'id'
        //     }
        //   ]
        let mergeByrailwayId = mergeCellsByrailwayId(mergeData, 1, 1, [])
        let mergeByoriginatingId = mergeCellsByoriginatingId(mergeData, 1, 1, [])
        mergeRules.value = mergeCells(mergeData, 1, 1, []).concat(mergeByoriginatingId, mergeByrailwayId)
        // 先合并后赋值
        waybillDuplicatedData.value = mergeData
      } else {
        errorCode.value = response.errorCode
        match_loading.value = false
        switchErrorType(response)
      }
    }).catch(() => {
      match_loading.value = false
    })
  })
}

/** 递归函数合并到端数据 */
function mergeCells(data, startRow = 1, rowSpan = 1, mergeCellRule = []) {
  // 1.如果数据为空，返回空数组
  if (!data.length) return [];
  // 获取当前行和下一行的数据
  const currentRow = data[startRow - 1];
  const nextRow = data[startRow];
  // 2.判断当前行和下一行是否相同
  const isSameRow = [
    'receiptPlateNo',
    'receiptWeightBillNo',
    'receiptContainerNo',
    'receiptWeightingDate',
  ].every((key) => currentRow[key] == nextRow?.[key]);
  // 3.如果当前行和下一行相同，递归调用函数
  if (isSameRow) {
    return mergeCells(data, startRow + 1, rowSpan + 1, mergeCellRule);
  }
  // 4.如果当前行和下一行不同，将当前行的合并规则添加到 mergeCellRule 数组中
  else {
    if (rowSpan > 1) {
      mergeCellRule.push(
        { row: startRow - rowSpan, rowspan: rowSpan, col: 1, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 2, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 3, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 4, colSpan: 1 }
      );
    }
  }
  // 5.如果下一行存在，递归调用函数
  if (nextRow) {
    return mergeCells(data, startRow + 1, 1, mergeCellRule);
  }
  // 如果下一行不存在，返回 mergeCellRule 数组
  return mergeCellRule;
}
/** 递归函数合并发端数据 */
function mergeCellsByoriginatingId(data, startRow = 1, rowSpan = 1, mergeCellRule = []) {
  // 1.如果数据为空，返回空数组
  if (!data.length) return [];
  // 获取当前行和下一行的数据
  const currentRow = data[startRow - 1];
  const nextRow = data[startRow];
  // 2.判断当前行和下一行是否相同
  const isSameRow = ['originatingId',].every((key) => currentRow[key] == nextRow?.[key] && currentRow[key] !== null && nextRow?.[key] !== null);
  // 3.如果当前行和下一行相同，递归调用函数
  if (isSameRow) {
    return mergeCellsByoriginatingId(data, startRow + 1, rowSpan + 1, mergeCellRule);
  }
  // 4.如果当前行和下一行不同，将当前行的合并规则添加到 mergeCellRule 数组中
  else {
    if (rowSpan > 1) {
      mergeCellRule.push(
        { row: startRow - rowSpan, rowspan: rowSpan, col: 5, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 6, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 7, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 8, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 9, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 10, colSpan: 1 },
      );
    }
  }
  // 5.如果下一行存在，递归调用函数
  if (nextRow) {
    return mergeCellsByoriginatingId(data, startRow + 1, 1, mergeCellRule);
  }
  // 如果下一行不存在，返回 mergeCellRule 数组
  return mergeCellRule;
}
/** 递归函数合并铁路数据 */
function mergeCellsByrailwayId(data, startRow = 1, rowSpan = 1, mergeCellRule = []) {
  // 1.如果数据为空，返回空数组
  if (!data.length) return [];
  // 获取当前行和下一行的数据
  const currentRow = data[startRow - 1];
  const nextRow = data[startRow];
  // 2.判断当前行和下一行是否相同
  const isSameRow = ['railwayId',].every((key) => currentRow[key] == nextRow?.[key] && currentRow[key] !== null && nextRow?.[key] !== null);
  // 3.如果当前行和下一行相同，递归调用函数
  if (isSameRow) {
    return mergeCellsByrailwayId(data, startRow + 1, rowSpan + 1, mergeCellRule);
  }
  // 4.如果当前行和下一行不同，将当前行的合并规则添加到 mergeCellRule 数组中
  else {
    if (rowSpan > 1) {
      mergeCellRule.push(
        { row: startRow - rowSpan, rowspan: rowSpan, col: 11, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 12, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 13, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 14, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 15, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 16, colSpan: 1 },
        { row: startRow - rowSpan, rowspan: rowSpan, col: 17, colSpan: 1 }
      );
    }
  }
  // 5.如果下一行存在，递归调用函数
  if (nextRow) {
    return mergeCellsByrailwayId(data, startRow + 1, 1, mergeCellRule);
  }
  // 如果下一行不存在，返回 mergeCellRule 数组
  return mergeCellRule;
}

/** 匹配错误类型 */
function switchErrorType(result) {
  if (result.errorCode == 'FormDataError') {
    errorList.value = result.data
  }
  else if (result.errorCode == 'DuplicateReceiptData') {
    if (result.data) {
      duplicateData.value = result.data
    } else {
      duplicateData.value = []
      duplicate_content.value = `系统检测到您导入的Excel文件中存在重复数据。
      这些数据可能已经在之前的对账中被处理过，请检查文件内容，避免重复对账`
    }
  } else {
    ElMessage({ message: result.message, type: 'error', duration: 1500 })
  }
}

/** 下载导入模板 */
function downloadTemplate() {
  const link = document.createElement('a');
  link.href = 'https://bituo-logistics-saas.oss-cn-beijing.aliyuncs.com/web/excel/template/%E5%88%B0%E7%AB%AF%E6%95%B0%E6%8D%AE%E6%A8%A1%E6%9D%BF.xlsx'
  link.download = '到端数据模板.xlsx';
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}

/** 返回匹配数据页面 */
function goBcak() {
  recoverPageStatus()
}

/** 关闭生成成功之后的页面 */
function closeSuccessPage() {
  clearPage()
}

/** 回到初始页面 */
function recoverPageStatus() {
  activePage.value = 'first'
  // 清空匹配结果表格数据
  resultData.value = []
  waybillUnmatchedData.value = []
  waybillDuplicatedData.value = []
}


getRouteSimpleList()
</script>

<style lang='scss' scoped>
@import '../../../../assets/styles/variables.module.scss';

.app-main-box {
  background: #fff;
  border-radius: 12px;
  min-height: calc(100vh - 125px);
  width: calc(100% - 40px);
  position: relative;

  :deep(.vxe-table-row) {
    height: 32px !important;
  }

  :deep(.el-checkbox.el-checkbox--large .el-checkbox__label) {
    font-size: 16px !important;
    font-weight: 500;
  }

  /** 功能按钮 */
  .func-btn {
    padding: 24px 24px 0px;
  }
}

/** 1.发起对账第一页相关样式(开始匹配) */
.page-first-container {
  padding: 0 40px;
}

.divider {
  border-bottom: 2px dashed $--color-bg-info;
}

.modal-content {
  padding: 30px 0px;
}

.select-file-content {
  display: flex;
}

.select-file-tip {
  font-size: 14px;
  color: $--color-info;
  margin-top: 14px;
}

.form-content {
  .preview-file-content {
    width: 500px;
    height: 50px;
    border-radius: 4px;
    background-color: $--color-bg-info;
    display: flex;
    align-items: center;
    padding: 5px 14px;

    .left {
      width: 40px;
      height: 40px;
    }

    .file-info {
      flex: 1;
      display: flex;
      flex-direction: column;
      margin-left: 14px;
      color: #333;

      .file-name {
        font-size: 14px;
      }

      .file-size {
        font-size: 12px;
        margin-top: 4px;
      }
    }

    .right {
      margin-left: 14px;
      display: flex;
      text-align: right;
      font-size: 22px;
      color: $--color-info;

      .delete-file {
        margin-left: 14px
      }

      .preview-file,
      .delete-file {
        cursor: pointer;
      }
    }
  }

  :deep(.el-form-item) {
    width: 528px !important;
  }
}

.label-wrap {
  display: flex;
  flex-wrap: nowrap;

  .label-text {
    height: 36px;
    text-align: justify;
    display: inline-block;
    width: 4em;
    color: #515a6e;
    font-weight: bold;

    &::after {
      display: inline-block;
      content: "-";
      width: 4em;
      opacity: 0;
    }
  }

  .label-single {
    width: max-content;
  }
}

:deep(.el-form-item.is-required:not(.is-no-asterisk).asterisk-left > .el-form-item__label:before) {
  content: "*";
  display: inline-block;
  width: 14px;
  height: 32px;
  text-align: center;
  line-height: 32px;
  color: $--color-danger;
  margin-right: 8px !important;
}

:deep(.el-upload-list) {
  display: none !important;
}

.trapezoid-box {
  width: 100% !important;
  display: flex !important;
  margin-bottom: 24px;
}

.upload-fail {
  margin-top: 20px;
}

.instructment-tip {
  font-size: 14px;
  // color: $--color-info;
  color: $--color-danger;
}

.upload-fail-table {
  width: 528px;
  height: 150px;
  margin-top: 10px;
  box-sizing: border-box;

  .infinite-list-wrapper {
    width: 100%;
    height: 100%;
    border-radius: 6px;
    background-color: $--color-bg-info;
    padding: 0px 14px;
    overflow-y: auto;
  }

  .list {
    padding: 0;
    margin: 0;
    list-style: none;

    .list-item {
      display: flex;
      align-items: flex-end;
      height: 30px;
      line-height: 30px;
      font-size: 12px;
      color: $--color-danger;
      white-space: nowrap;
    }
  }

  .list-message-container {
    padding: 0;
    margin: 0;
    list-style: none;

    .list-message {
      text-align: left;
      color: $--color-danger;
    }
  }
}


/** 2.匹配结果页面样式 */
.title-bar-container {
  display: flex;
  align-items: center;

  .el-icon {
    color: $--color-warning;
    font-size: 24px;
    padding: 0 12px;
    cursor: pointer;
  }
}

.match-data-container {
  margin-top: 30px;
}

.match-data-footer {
  margin: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 24px;
}

.form-generate {
  display: flex !important;
  flex-wrap: wrap;
  grid-gap: 0 20px;

  .form-items {
    width: calc(50% - 10px);
    align-items: center !important;

    .form-input {
      height: 36px !important;
      width: 100%;
    }
  }
}

.dialog-footer {
  margin-top: 24px;
  text-align: right;
}

.flex-space-between {
  width: calc(100% - 48px) !important;
  display: flex;
  align-items: center;

  .flex-right {
    flex: 1;
    justify-self: flex-end !important;
    text-align: right;

    .el-button {
      margin: 0 !important;
    }
  }
}

/** 3.匹配成功之后的页面 */
.page-third-container {
  width: 100%;
  height: calc(100vh - 135px);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: absolute;
  top: 20%;

  .operate-title {
    color: #333;
    font-weight: 500;
    font-size: 20px;
    margin: 20px 0px 20px;
  }

  .operate-text {
    color: $--color-info;
    font-size: 16px;
  }

  .btn-list {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 50px;

    .el-button {
      min-width: 100px;
      margin: 0 20px;
    }
  }
}
</style>
